(function($) {

    $.fn.tinymenu = function(mtext) {
    	var id = '#' + $(this).attr("id");
    	var select 	= id + ' select';
    	var li 	= id + ' > ul > li:not([data-toggle])';
    	var txt = mtext;
    	if(!txt) {
    		var txt = 'Go to...';
    	} else {
    		var txt = mtext;
    	}
        $("<select />").appendTo(id);
        $("<option />",{"selected":"selected","value":"","text":txt}).appendTo(select);
        $(li).each(function(){
        	var el=$(this);
        	var hasChildren=el.find("ul"),children=el.find("li > a");
        	if(hasChildren.length){
        		$("<optgroup />",{"label":el.find("> a").text()}).appendTo(select);
        		children.each(function(){
        			$("<option />",{"value":$(this).attr("href"),"text":" - "+ $(this).text()}).appendTo("optgroup:last");
        		});
        	}
        	else{
        		$("<option />",{"value":el.find("> a").attr("href"),"text":el.find("> a").text()}).appendTo(select);
        	}
        });
        $(select).change(function(){
        	window.location=$(this).find("option:selected").val();
        });

    }

}(jQuery));